<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>AdminLTE 2 | Log in</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="../public/bower_components/bootstrap/dist/css/bootstrap.min.css"   th:href="@{/bower_components/bootstrap/dist/css/bootstrap.min.css}">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../public/bower_components/font-awesome/css/font-awesome.min.css"  th:href="@{/bower_components/font-awesome/css/font-awesome.min.css}">
  <!-- Ionicons -->
  <link rel="stylesheet" href="../public/bower_components/Ionicons/css/ionicons.min.css"           th:href="@{/bower_components/Ionicons/css/ionicons.min.css}">
  <!-- Theme style -->
  <link rel="stylesheet" href="../public/dist/css/AdminLTE.min.css"                                   th:href="@{/dist/css/AdminLTE.min.css}">
  <!-- iCheck -->
  <link rel="stylesheet" href="../public/plugins/iCheck/square/blue.css"                             th:href="@{/plugins/iCheck/square/blue.css}">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <!--<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>-->
  <!--<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>-->
  <![endif]-->

  <!-- Google Font -->
  <!--<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">-->
  <style type="text/css">
    .captcha-img{
      padding: 0;
      cursor: pointer;
    }

    .glyphicon-eye-close,.glyphicon-eye-open{
      pointer-events: auto;
      cursor: pointer;
    }
  </style>
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <span><b>Admin</b>LTE</span>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">Sign in to start your session</p>

    <form action="login" method="post">
      <div class="form-group has-feedback">
        <input name="username" type="text" class="form-control" placeholder="用户名">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input name="password" type="password" class="form-control" placeholder="密    码" autocomplete="new-password">
        <span class="glyphicon glyphicon-eye-close form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="form-group">
            <img class="form-control captcha-img" th:src="@{/captcha(type=${CAPTCHA_TYPE})}">
          </div>
        </div>
        <div class="col-xs-4">
          <div class="form-group">
            <input type="text" id="captcha" name="captcha" class="form-control text-center" placeholder="验证码">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input name="rememberMe" type="checkbox"> 记住我
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
    <br>
    <br>
    <br>
    <div class="container-fluid">
      <div class="row">
        <div class="col-xs-12 text-center">
          <a href="register" class="text-center">没有账号?前往注册</a>
        </div>
      </div>
    </div>
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script src="../public/bower_components/jquery/dist/jquery.min.js"             th:src="@{/bower_components/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../public/bower_components/bootstrap/dist/js/bootstrap.min.js"   th:src="@{/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
<!-- iCheck -->
<script src="../public/plugins/iCheck/icheck.min.js"                             th:src="@{/plugins/iCheck/icheck.min.js}"></script>
<!--jQuery.Validate及语言包-->
<script src="../static/libs/jquery/validate/jquery.validate.min.js"  th:src="@{/libs/jquery/validate/jquery.validate.min.js}">    </script>
<script src="../static/libs/jquery/validate/messages_zh.min.js"       th:src="@{/libs/jquery/validate/messages_zh.min.js}"    >   </script>
<!--弹出层-->
<script src="../static/libs/layer/layer.min.js"                         th:src="@{/libs/layer/layer.min.js}">                        </script>
<!--自定义通用库-->
<script src="../static/js/common.js"                                      th:src="@{/js/common.js}">                                   </script>
<script>
   "use strict";

  $(function () {
      //记住我Checkbox
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' /* optional */
    });

    //点击更换验证码功能
     $(".captcha-img").click(function () {
         let src = $(this).attr("src")
         $(this).attr("src", src + "&s=" + Math.random())
     })

     //验证Form
     var ctx = "/"
     $("form").validate({
          //验证规则
          rules:{
              username:{
                  required:true,          //必须存在用户名
                  rangelength: [4, 16],   //用户名长度限制
              },
              password:{
                  required:true,
                  rangelength: [6, 32],
              },
              captcha:{
                  required:true,           //必须存在
                  remote: {                 //服务器验证是否唯一
                      url: ctx + "captcha",   //远程验证Url
                      type: "post",                          //POST
                      dataType: "json",                     //预期服务器返回的类型
                      data: {                                 //请求数据
                          code : function() {
                              return $.trim($("#captcha").val());
                          }
                      }
                  }
              }
          },
          messages: {
              "captcha": {
                  remote: '验证码不正确'
              }
          },
          //验证失败时高亮显示
          highlight: function(input, errorClass, validClass){
              $(input).parent().addClass("has-error");
          },
          //验证成功时消除高亮显示
          unhighlight: function(input, errorClass, validClass){
              $(input).parent().removeClass("has-error");
          },
          //Field错误信息放置地点
          errorPlacement: function(errorLabel, input){
              errorLabel.insertAfter($(input).parent())
          },
          submitHandler:function(form) {
              let $form = $(form);
              $.post($form.attr('action'), $form.serialize(), function () {
                  $.modal.msgSuccess("登陆成功,跳转到主页...");
                  setTimeout(function () {
                      window.location.href = "/";
                  }, 2000);
              });
          }
      })
  });
</script>
</body>
</html>
